//
// Created by xili on 2024/8/8 11:43.
// Go big or go home.
//
#include <vector>

using namespace std;


class Solution {
public:
    //前缀和数组
    vector<int> pre;

    int sumOddLengthSubarrays(vector<int> &arr) {
        build(arr);
        int n = arr.size();
        long ans = 0;
        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n + 1; j += 2) {
                ans += sum(i, j);
            }
        }
        return ans;
    }

    void build(vector<int> &nums) {
        int n = nums.size() + 1;
        pre.resize(n);
        //0这个前缀和在没有任何数之前就已经出现了
        pre[0] = 0;
        for (int i = 1; i < n; i++) {
            pre[i] = pre[i - 1] + nums[i - 1];
        }
    }

    int sum(int x, int y) {
        return pre[y] - pre[x];
    }
};